package com.expmanage.actions.manager;

import org.apache.ibatis.session.*;

import com.expmanage.models.*;
import com.opensymphony.xwork2.*;
import static com.expmanage.actions.utils.DatabaseConfigure.*;

@SuppressWarnings("serial")
public class tRegist extends ActionSupport{
	private String name, email, password;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	private String Register() {
		SqlSession session = sqlSessionFactory.openSession();
		try {
			Teacher newTeacher = new Teacher(name, email, password);
			TeacherMapper mapper = session.getMapper(TeacherMapper.class);
			mapper.addTeacher(newTeacher);
			session.commit();
		} catch(Throwable e){
			e.printStackTrace();
			return "error";
		}finally {
			session.close();
		}
		return "success";
	}
	
	public String execute() {
		return Register();
	}
}
